#!/bin/bash
# SPDX-License-Identifier: GPL-2.0-or-later
# Fedora-adapted launcher for GPcal (https://github.com/cdeletre/GPcal).
#
# ROCKNIX shipped a pre-built read-only Python venv with pyxel inside the read
# /usr filesystem. On a writable Fedora userland we instead create a per-user
# venv on first run, then exec into it.

set -e

GPCAL_PATH="/usr/share/gpcal"
VENV="${XDG_DATA_HOME:-$HOME/.local/share}/gpcal/venv"

if [ ! -x "${VENV}/bin/python3" ]; then
    echo "GPcal: setting up per-user venv at ${VENV} ..." >&2
    python3 -m venv "${VENV}"
    "${VENV}/bin/pip" install --quiet --upgrade pip
    "${VENV}/bin/pip" install --quiet pyxel
fi

# main.py uses relative imports + reads gamedata/ from CWD
cd "${GPCAL_PATH}"
exec env PYTHONDONTWRITEBYTECODE=1 "${VENV}/bin/python3" main.py "$@"
